import Vue from 'vue'
import Router from 'vue-router'
import Layout from '@/layout' // 布局页

Vue.use(Router)

// 通用页面：不需要守卫，可直接访问
export const constRoutes = [
  //登录页
  {
    path: '/login',
    component: () => import('@/views/Login'),
    hidden: true, // 导航菜单忽略该项
  },
  //添加商品
  {
    path: '/addshop',
    component: Layout, // 应用布局
    redirect: '/addshop/index',
    hidden: true, // 导航菜单忽略该项
    children: [
      {
        path: 'index',
        name: 'addshopindex',
        component: () => import('@/views/shopAdmin/children/index.vue'),
        meta: {
          title: '添加商品', // 导航菜单项标题
          icon: 'qq', // 导航菜单项图标
        },
      },
    ],
    name: 'addshop',
    meta: {
      title: '添加商品', // 导航菜单项标题
      icon: 'qq', // 导航菜单项图标
    },
  },
  {
    path: '/Theone',
    component: Layout, // 应用布局
    redirect: '/Theone/index',
    hidden: true, // 导航菜单忽略该项
    children: [
      {
        path: 'index',
        name: 'index',
        component: () => import('@/views/barteringGoods/TheOne.vue'),
        meta: {
          title: '添加商品', // 导航菜单项标题
          icon: 'qq', // 导航菜单项图标
        },
      },
    ],
    name: 'theone',
    meta: {
      title: '砍价商品', // 导航菜单项标题
      icon: 'qq', // 导航菜单项图标
    },
  },
  {
    path: '/addshop',
    component: Layout, // 应用布局
    redirect: '/addshop/index',
    hidden: true, // 导航菜单忽略该项
    children: [
      {
        path: 'index',
        name: 'addshopindex',
        component: () => import('@/views/shopAdmin/children/index.vue'),
        meta: {
          title: '添加商品', // 导航菜单项标题
          icon: 'qq', // 导航菜单项图标
        },
      },
    ],
    name: 'addshop',
    meta: {
      title: '添加商品', // 导航菜单项标题
      icon: 'qq', // 导航菜单项图标
    },
  },
  {
    path: '/One',
    component: Layout, // 应用布局
    redirect: '/One/index',
    hidden: true, // 导航菜单忽略该项
    children: [
      {
        path: 'index',
        name: 'index',
        component: () => import('@/views/group/TheOne.vue'),
        meta: {
          title: '添加商品', // 导航菜单项标题
          icon: 'qq', // 导航菜单项图标
        },
      },
    ],
    name: 'theone',
    meta: {
      title: '砍价商品', // 导航菜单项标题
      icon: 'qq', // 导航菜单项图标
    },
  },
  // 工作台
  {
    path: '/',
    component: Layout, // 应用布局
    redirect: '/home',
    meta: { title: '工作台', icon: 'qq', breadcrumb: false },
    children: [
      {
        path: 'home',
        component: () => import('@/views/workBench/index.vue'),
        name: 'home',
        meta: {
          title: '工作台', // 导航菜单项标题
          icon: 'gzt', // 导航菜单项图标
        },
      },
    ],
  },
  //商品
  {
    path: '/layout',
    component: Layout, // 应用布局
    redirect: '/layout/shopadmin',
    meta: { title: '商品', icon: 'shop', breadcrumb: false },
    children: [
      {
        path: 'shopadmin',
        component: () => import('@/views/shopAdmin/index.vue'),
        name: 'shopadmin',
        meta: {
          title: '商品管理', // 导航菜单项标题
          icon: 'rule', // 导航菜单项图标
        },
      },
      {
        path: 'shoprule',
        component: () => import('@/views/shopRule/index.vue'),
        name: 'shoprule',
        meta: {
          title: '商品规格', // 导航菜单项标题
          icon: 'specifications', // 导航菜单项图标
        },
      },
      {
        path: 'shoptype',
        component: () => import('@/views/shopType/index.vue'),
        name: 'shoptype',
        meta: {
          title: '商品分类', // 导航菜单项标题
          icon: 'class', // 导航菜单项图标
        },
      },
      {
        path: 'shopsay',
        component: () => import('@/views/shopSay/index.vue'),
        name: 'shopsay',
        meta: {
          title: '商品评价', // 导航菜单项标题
          icon: 'say', // 导航菜单项图标
        },
      },

    ],
  },
  //营销
  {
    path: '/kill',
    component: Layout,
    redirect: '/kill/index',
    meta: { title: '营销', icon: 'marketing', breadcrumb: false },
    children: [
      //秒杀
      {
        path: 'index',
        component: () => import('@/layout/kill.vue'),
        name: 'kill',
        meta: { title: '秒杀', icon: 'kill', breadcrumb: false },
        children: [
          {
            path: 'killcon',
            component: () => import('@/views/killCon/index.vue'),
            name: 'killcon',
            meta: {
              title: '秒杀配置',
              icon: 'killshop',
            },
          },
          {
            path: 'killshop',
            component: () => import('@/views/killShop/index.vue'),
            name: 'killshop',
            meta: {
              title: '秒杀商品',
              icon: 'seckill',
            },
          },
        ],
      },
      //砍价
      {
        path: 'index2',
        component: () => import('@/layout/kill.vue'),
        name: 'kill',
        meta: {
          title: '砍价管理',
          icon: 'administration',
          breadcrumb: false,
        },
        children: [
          {
            path: 'barteringGoods',
            component: () => import('@/views/barteringGoods/index.vue'),
            name: 'index',
            meta: {
              title: '砍价商品',
              icon: 'killsome',
            },
          },
          {
            path: 'cutpriceList',
            component: () => import('@/views/cutpriceList/index.vue'),
            name: 'index',
            meta: {
              title: '砍价列表',
              icon: 'killlist',
            },
          },
        ],
      },
      //直播
      {
        path: 'index3',
        component: () => import('@/layout/kill.vue'),
        name: 'live',
        meta: {
          title: '直播管理',
          icon: 'administration',
          breadcrumb: false,
        },
        children: [
          {
            path: 'livelist',
            component: () => import('@/views/Live/liveList.vue'),
            name: 'index',
            meta: {
              title: '直播列表',
              icon: 'killsome',
            },
          },
          {
            path: 'livedetail',
            component: () => import('@/views/Live/liveDetail.vue'),
            name: 'index',
            hidden: true,
            meta: {
              title: '直播详情',
              icon: 'killsome',
            },
          },
          {
            path: 'createlive',
            component: () => import('@/views/Live/createLive.vue'),
            name: 'index',
            meta: {
              title: '创建直播',
              icon: 'killlist',
            },
          },

        ],
      },
      {
        path: 'index4',
        component: () => import('@/layout/kill.vue'),
        name: 'group',
        meta: {
          title: '拼团管理',
          icon: 'administration',
          breadcrumb: false,
        },
        children: [
          {
            path: 'groupshop',
            component: () => import('@/views/group/groupShop.vue'),
            name: 'index',
            meta: {
              title: '拼团商品',
              icon: 'killsome',
            },
          },
          {
            path: 'grouplist',
            component: () => import('@/views/group/groupList.vue'),
            name: 'index',
            meta: {
              title: '拼团列表',
              icon: 'killlist',
            },
          },
        ],
      },
    ],
  },
  {
    path: "/liveing",
    component: () => import("@/views/Live/liveing.vue")
  }
]

// 权限页面：受保护页面，要求用户登录并拥有访问权限的角色才能访问
export const asyncRoutes = [
  {
    path: '/about',
    component: Layout,
    redirect: '/about/index',
    children: [
      {
        path: 'index',
        component: () => import('@/views/About.vue'),
        name: 'about',
        meta: {
          title: '管理员',
          icon: 'admin',
          roles: ['admin'],
        },
      },
    ],
  },
]

export default new Router({
  // mode: "history",
  base: process.env.BASE_URL,
  routes: constRoutes,
})

const originalPush = Router.prototype.push
Router.prototype.push = function push(location) {
  return originalPush.call(this, location).catch((err) => err)
}
